document.querySelector("#btn-login").addEventListener("click", async ()=>{
    // 发请求 接注册接口
    // axios({
    //     url: "/register",
    //     method: "post",
    //     data:{
    //         username: "jack",
    //         password:"123456"
    //     }
    // })
    const form = document.querySelector(".login-form")
    const data =serialize(form,{empty:true,hash:true})
    const {username,password} = data
    if(username === '' || password === ''){
        showToast("用户名或密码不能为空")
        return
    }
    //长度验证
    if(username.length<8||username.length>30||password.length<6||password.length>30)
{
    showToast("用户名或密码格式不正确")
    return
}
//数据提交

// try{
    const res = await axios.post('/register',{username,password})
   showToast(res.message)
   //缓存数据
   localStorage.setItem("token",res.data.token)
   localStorage.setItem("username",res.data.username)

setTimeout(()=>{
    window.location.href = "./index.html"
},1500)
// }catch(error){
//     showToast(error.response.data.message)
// }
  

})

